package C;

import java.util.Scanner;

public class C41 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String[] s = new String[n];
        for (int i=0;i<n;i++) {
            s[i] = sc.nextLine();
        }
        getResult(s);
    }
    public static void getResult(String[] s) {
        for (int i=0;i<s.length;i++) {
            String[] record = s[i].split(" ");
            System.out.println(isAward(record));
        }
    }
    public static boolean isAward(String[] record) {
        int absent = 0;
        int present = 0;
        String preRecord = "";

        for (int i=0;i<record.length;i++) {
            if (i>=7) {
                if ("present".equals(record[i-7])) present--;
            }

            String curRecord = record[i];
            switch (curRecord) {
                case "absent":
                    if (++absent > 1) return false;
                    break;
                case "late":
                case "leaveearly":
                    if ("late".equals(preRecord) || "leaveearly".equals(preRecord)) return false;
                    break;
                case "present":
                    present++;
                    break;
            }

            preRecord = curRecord;

            int window_len = Math.min(i+1,7);
            if (window_len-present>3) return false;
        }

        return true;
    }
}
